/*
 * Copyright (c) 2023 AlgoIdeas
 *
 * HDF is dual licensed: you can use it either under the terms of
 * the GPL, or the BSD license, at your option.
 * See the LICENSE file in the root of this repository for complete details.
 */

#include "aht20-d.h"
#include <stdio.h>
#include <unistd.h>

#define AHT20_I2C_IDX   5

int main(int argc, char *argv[])
{
    int ret = 0;
    float temp = 0.0, humi = 0.0;

    int fp = aht20_open(AHT20_I2C_IDX, AHT20_DEVICE_ADDR);
    if (fp == -1) {
        printf("aht20_open i2c-%d fail!\n", AHT20_I2C_IDX);
        return -1;
    }

    aht20_calibrate(fp);

    for (;;)
    {
        ret = aht20_start_measure(fp);
        if (ret == -1) {
            printf("aht20_start_measure fail!\n");
            sleep(1);
            continue;
        }
        
        ret = aht20_get_measure_result(fp, &temp, &humi);
        printf("temp = %.2f, humi = %.2f\n", temp, humi);

        sleep(1);
    }

    return 0;
}

